package service;

import constant.ConstRole;
import constant.ConstWebPage;
import pond.common.S;
import pond.common.STRING;

import java.util.*;

/**
 * Created by sky_wang on 2017/7/13.
 */
public class WebPageService {
    private static Map<ConstRole, String> roleAccessPageMap = new HashMap<ConstRole, String>(){
        {
            put(ConstRole.ROLE_VIEW_CREATED,ConstWebPage.VIEW_CREATED);
            put(ConstRole.ROLE_VIEW_DELETED,ConstWebPage.VIEW_DELETED);
            put(ConstRole.ROLE_RELATIONSHIP_UPDATE,ConstWebPage.RELATIONSHIP_UPDATE);
            put(ConstRole.ROLE_REPORT_DESIGNED,ConstWebPage.REPORT_DESIGNED);
            put(ConstRole.ROLE_REPORT_CONSULTED,ConstWebPage.REPORT_CONSULTED);
        }
    };
    private static Map<ConstRole,String> roleAccessDivMap= new HashMap<ConstRole,String>(){
        {
            put(ConstRole.ROLE_VIEW_CREATED,            ConstWebPage.DIV_VIEW_CREATED);
            put(ConstRole.ROLE_VIEW_DELETED,            ConstWebPage.DIV_VIEW_DELETED);
            put(ConstRole.ROLE_RELATIONSHIP_UPDATE,     ConstWebPage.DIV_RELATIONSHIP_UPDATE);
            put(ConstRole.ROLE_REPORT_DESIGNED,         ConstWebPage.DIV_REPORT_DESIGNED);
            put(ConstRole.ROLE_REPORT_CONSULTED,        ConstWebPage.DIV_REPORT_CONSULTED);
        }
    };

    public static boolean isAllowed(List<ConstRole> roleList, String page){
        if (STRING.isBlank(page))
        {
            return false;
        }

        for (ConstRole role : roleList)
        {
            if (page.equals(roleAccessPageMap.get(role)))
            {
                return true;
            }
        }
        return  false;
    }

    public static String getIndexPageDivContent(List<ConstRole> roleList){
        String divContent ="";
        for (ConstRole role : roleList)
        {
            divContent += roleAccessDivMap.get(role);
        }
        return divContent;
    }
}
